package com.example.gulimall.order.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.gulimall.order.entity.RefundInfoEntity;
import com.example.gulimall.order.service.RefundInfoService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * 退款信息
 *
 * @author zyred
 * @email zyred@163.com
 * @date 2021-08-23 11:54:53
 */
@RestController
@RequestMapping("order/refundinfo")
public class RefundInfoController {
    @Autowired
    private RefundInfoService refundInfoService;

    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = refundInfoService.queryPage(params);
        return R.ok().put("page", page);
    }


    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		RefundInfoEntity refundInfo = refundInfoService.getById(id);
        return R.ok().put("refundInfo", refundInfo);
    }

    @RequestMapping("/save")
    public R save(@RequestBody RefundInfoEntity refundInfo){
		refundInfoService.save(refundInfo);
        return R.ok();
    }

    @RequestMapping("/update")
    public R update(@RequestBody RefundInfoEntity refundInfo){
		refundInfoService.updateById(refundInfo);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		refundInfoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 284视频小结：使用 Spring Bean 来代替老师的 AspectJ 实验（同一个service内，方法连续调用，使用不同的事务）
     * 1. 原事务中调用插入数据库的逻辑，并且新事务处理完毕后，抛出异常
     * 2. 新事务中向数据库中插入数据，当原事务发生异常时，新事务并不会回滚
     */
    @GetMapping("/tranTest")
    public void tranTest () {
        this.refundInfoService.tranTest();
    }

}
